package com.hl.sfzy.service;

import com.hl.sfzy.entity.LogonUser;
import com.hl.sfzy.mapper.LogonUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: sfzy
 * @description: 孙源源-用户登录
 * @author: Syy
 * @create: 2024-09-05 17:58
 **/
@Service
public class LogonUserService {
    @Autowired
    private LogonUserMapper logonUserMapper;

    public LogonUser logon(String identifier, String password) {
        boolean isPhone = identifier.matches("\\d{11}");
        LogonUser user = isPhone ? logonUserMapper.findLogonUserByPhone(identifier) : logonUserMapper.findLogonUserByUsername(identifier);

        if (user != null && user.getRole() == 3 && user.getPassword().equals(password)) {
            return user; // 登录成功，返回用户对象
        }
        return null; // 登录失败
    }
}
